package com.dm.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dm.shop.common.enums.ResultEnum;
import com.dm.shop.entity.Address;
import com.dm.shop.mapper.AddressMapper;
import com.dm.shop.service.AddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dm.shop.utils.ResultUtil;
import com.dm.shop.vo.Result;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author MyBatisPlusGenerater-Saiya Wang
 * @since 2021-07-20
 */
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements AddressService {

    @Override
    public Result addAddressInfo(Address address) {
        boolean IsSave =this.save(address);
        if(IsSave!=true){
            return ResultUtil.error(ResultEnum.FAIL);
        }
        else {
            return ResultUtil.success(ResultEnum.SUCCESS);
        }
    }

    @Override
    public Result editAddress(Address address) {
        boolean IsUpdate=this.updateById(address);
        if(IsUpdate!=true)
        {
            return ResultUtil.error(ResultEnum.FAIL);
        }
        else {
            return ResultUtil.success(ResultEnum.SUCCESS);

        }
    }

    @Override
    public Result delAddress(int id) {
        boolean IsRemove=this.removeById(id);
        if(IsRemove!=true)
        {
            return ResultUtil.error(ResultEnum.FAIL);
        }
        else {
            return ResultUtil.success(ResultEnum.SUCCESS);

        }
    }

    @Override
    public Result getAllAddress(int uid) {
        QueryWrapper<Address> wrapper=new QueryWrapper<>();
        wrapper.like("uid",uid);
        List<Address> addressList=this.list(wrapper);
        if(addressList!=null){
            return ResultUtil.success(addressList);
        }
        else {
            return ResultUtil.error(ResultEnum.FAIL);
        }
    }
}
